Skip to content

fix(vec2svg): deduplicate raster image resources - #884

Open
syrkis wants to merge 2 commits into
Myriad-Dreamin:mainfrom
syrkis:fix/deduplicate-svg-raster-images
Open

fix(vec2svg): deduplicate raster image resources#884
syrkis wants to merge 2 commits into
Myriad-Dreamin:mainfrom
syrkis:fix/deduplicate-svg-raster-images

Conversation

@syrkis

@syrkis syrkis commented Aug 5, 2026

Copy link
Copy Markdown

Closes #883

Summary

Deduplicate repeated PNG, JPEG, GIF, and WebP resources in reflexo-vec2svg.

Raster images are now emitted once in SVG definitions and placements reference the shared resource with <use>. Resource
identity is based on the image format and encoded bytes, while placement-specific sizing, transforms, alt text, and
image-rendering remain on each placement.

Vector images retain the existing inline rendering path. Resource definitions remain scoped to each independently usable
SVG document.

Motivation

Previously, every placement embedded its own Base64 payload. Documents that reused large raster images could therefore
produce very large SVG output.

For the 100-placement regression case, the embedded payload count decreases from 100 to 1.

Compatibility

Both href and xlink:href are emitted for image references. The generated SVG remains self-contained, and independently
exported documents do not share definitions.

Testing

Added coverage for:

  • repeated identical images;
  • distinct image data;
  • different placement sizes and transforms;
  • placement-specific alt text and pixelated rendering;
  • valid PNG, JPEG, GIF, and WebP fixtures;
  • vector images remaining inline;
  • documents without raster images;
  • 100 repeated placements.

Validated with:

  • cargo fmt --all --check
  • cargo test -p reflexo-vec2svg
  • cargo clippy -p reflexo-vec2svg --all-targets --all-features -- -D warnings
  • cargo build -p reflexo-vec2svg

Incremental rendering

The browser-side SVG resource patcher now retains image definitions introduced by incremental updates.

This covers the case where a watched raster file changes and receives a new stable resource ID. The updated <use> reference now resolves to the newly installed definition without refreshing the document.

Validated with:

  • a focused browser regression test;
  • a live Tinymist preview using rollout.webp → rollout_2.webp → rollout.webp;
  • zero unresolved raster resource references throughout both transitions.

@syrkis syrkis closed this Aug 5, 2026
@syrkis

syrkis commented Aug 5, 2026

Copy link
Copy Markdown
Author

Tinymist integration is available in Myriad-Dreamin/tinymist#2686.
It exercises the deduplicated SVG exporter and includes the
incremental resource
patch required when watched raster images change identity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deduplicate repeated raster images in SVG output

1 participant